home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Lib / test / testfinderopen.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  768 b   |  34 lines

  1. """Make the finder open an application, file or folder"""
  2.  
  3. import Finder_7_0_Suite
  4. import aetools
  5. import MacOS
  6. import sys
  7. import macfs
  8.  
  9. SIGNATURE='MACS'
  10.  
  11. class Finder(aetools.TalkTo, Finder_7_0_Suite.Finder_7_0_Suite):
  12.     pass
  13.     
  14. def open_in_finder(file):
  15.     """Open a file thru the finder. Specify file by name or fsspec"""
  16.     finder = Finder(SIGNATURE)
  17.     fss = macfs.FSSpec(file)
  18.     vRefNum, parID, name = fss.as_tuple()
  19.     dir_fss = macfs.FSSpec((vRefNum, parID, ''))
  20.     file_alias = fss.NewAlias()
  21.     dir_alias = dir_fss.NewAlias()
  22.     return finder.open(file_alias, items=[file_alias])
  23.  
  24. def main():
  25.     fss, ok = macfs.PromptGetFile('File to launch:')
  26.     if not ok: sys.exit(0)
  27.     result = open_in_finder(fss)
  28.     if result:
  29.         print 'Result: ', result
  30.         
  31. if __name__ == '__main__':
  32.     main()
  33.     
  34.